package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.IdentifyAddDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Identify;
import com.hbnu.system.model.entity.Identifyfile;
import com.hbnu.system.service.IIdentifyService;
import com.hbnu.system.service.IIdentifyfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/identify")
@Api(tags = "成果鉴定模块")
public class IdentifyController {
    @Autowired
    IIdentifyService iidentifyService;
    @Autowired
    IIdentifyfileService iIdentifyfileService;

    @ApiOperation("鉴定-初次录入")
    @PostMapping("/addIdentifyDTO")
    public Rest<Boolean> addIdentifyDTO(@RequestBody IdentifyAddDTO identifyAddDTO){
        boolean add = iidentifyService.addIdentify(identifyAddDTO);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("鉴定-正式录入")
    @PostMapping("/addIdentify")
    public Rest<Boolean> addIdentify(@RequestBody Identify identify){
        boolean add = iidentifyService.addIdentify(identify);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("鉴定-删除")
    @GetMapping("/DeleteIdentify")
    public Rest<Boolean> DeleteIdentify(String IdentifyID){
        boolean delete = iidentifyService.deleteIdentify(IdentifyID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("鉴定-修改")
    @PostMapping("/UpdateIdentify")
    public Rest<Boolean> UpdateIdentify(Identify identify){
        boolean update = iidentifyService.updateIdentify(identify);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("鉴定-提交")
    @GetMapping("/CommitIdentify")
    public Rest<Boolean> CommitIdentify(String identifyID){
        boolean add = iidentifyService.CommitIdentify(identifyID);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键鉴定查询")
    @GetMapping("/GetIdentifyById")
    public Rest<Identify> GetIdentifyById(String identifyID){
        Identify identify = iidentifyService.getIdentify(identifyID);
        return Rest.success(identify);
    }

    @ApiOperation("鉴定-分页查询")
    @PostMapping ("/pagecondition")
    public Rest<CommonPage<Identify>> pageProjectCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Identify> page = iidentifyService.pageCondition(searchTaskDTO);
        CommonPage<Identify> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }

    @ApiOperation("论文-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePassIdentify(String PID){
        Boolean b = iidentifyService.collegeCheckPass(PID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("论文-院级退回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBackIdentify(@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iidentifyService.collegeCheckBack(checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("鉴定-校级通过")
    @GetMapping("/SchoolPassIdentify")
    public Rest<String> SchoolPassIdentify(String identifyID){
        Boolean b = iidentifyService.schoolCheckPass(identifyID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("鉴定-校级退回")
    @PostMapping("/SchoolBackIdentify")
    public Rest<String> SchoolBackIdentify(@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iidentifyService.schoolCheckBack(checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的鉴定-分页")
    @PostMapping("/UserGetRelateIdentify")
    public Rest<CommonPage<Identify>> UserGetRelateIdentify(@RequestBody UserDTO userDTO){
        IPage<Identify> identifyIPage = iidentifyService.userGetRelateIdentify(userDTO);
        CommonPage<Identify> identifyCommonPage = CommonPage.restPage(identifyIPage);
        return Rest.success(identifyCommonPage);
    }
    @ApiOperation("院级管理员查看需要自己审核的成果鉴定-分页")
    @PostMapping("/CollegeUserGetIdentify")
    public Rest<CommonPage<Identify>> CollegeUserGetIdentify(@RequestBody UserDTO userDTO){
        IPage<Identify> identifyIPage = iidentifyService.collegeUserGetIdentify(userDTO);
        CommonPage<Identify> paperCommonPage = CommonPage.restPage(identifyIPage);
        return Rest.success(paperCommonPage);
    }

    @ApiOperation("校级管理员查看需要自己审核的鉴定-分页")
    @PostMapping("/SchoolUserGetIdentify")
    public Rest<CommonPage<Identify>> SchoolUserGetIdentify(@RequestBody UserDTO userDTO){
        IPage<Identify> identifyIPage = iidentifyService.schoolUserGetIdentify(userDTO);
        CommonPage<Identify> identifyCommonPage = CommonPage.restPage(identifyIPage);
        return Rest.success(identifyCommonPage);
    }

    @ApiOperation("校级管理员查看自己已经审核的鉴定-分页")
    @PostMapping("/SchoolUserGetIdentifyOver")
    public Rest<CommonPage<Identify>> SchoolUserGetIdentifyOver(@RequestBody UserDTO userDTO){
        IPage<Identify> identifyIPage = iidentifyService.schoolUserGetIdentifyOver(userDTO);
        CommonPage<Identify> identifyCommonPage = CommonPage.restPage(identifyIPage);
        return Rest.success(identifyCommonPage);
    }
    @ApiOperation("院级管理员查看自己已经审核的成果鉴定-分页")
    @PostMapping("/CollegeUserGetIdentifyOver")
    public Rest<CommonPage<Identify>> CollegeUserGetIdentifyOver(@RequestBody UserDTO userDTO){
        IPage<Identify> identifyIPage = iidentifyService.collegeUserGetIdentifyOver(userDTO);
        CommonPage<Identify> identifyCommonPage = CommonPage.restPage(identifyIPage);
        return Rest.success(identifyCommonPage);
    }
    @ApiOperation("成果鉴定-文件信息上传")
    @PostMapping("/addIdentifyfile")
    public Rest<Boolean> addpaperfile(@RequestBody Identifyfile identifyfile){
        boolean add = iIdentifyfileService.addIdentifyfile(identifyfile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果鉴定-文件信息删除")
    @GetMapping("/DeleteIdentifyfile")
    public Rest<Boolean> Deletepaperfile(String identifyfileID)throws IOException {
        boolean delete = iIdentifyfileService.deletIdentifyfile(identifyfileID);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("成果鉴定-文件信息分页查询")
    @GetMapping ("/pageIdentifyfileCondition")
    public Rest<List<Identifyfile>> pagepaperfileConditionfile(String id){
        List<Identifyfile> page = iIdentifyfileService.pageIdentifyfile(id);
        return Rest.success(page);
    }
    @ApiOperation("成果鉴定-文件信息修改")
    @PostMapping("/updateIdentifyfile")
    public Rest<Boolean> updatepaperfile(@RequestBody Identifyfile identifyfile){
        boolean update = iIdentifyfileService.updateIdentifyfile(identifyfile);
        return update ? Rest.success() : Rest.failed();
    }
}

